<?php
include("../inc/global.inc");
include("islogin.php");
//获取文件后缀
function separation($file_name)
{
$retval="";
$pt=strrpos($file_name,"/");
if ($pt) $retval=substr($file_name,$pt+1,strlen($file_name)-$pt);
return ($retval);
}
function createFolders($path)   
{   
    if (!file_exists($path))
    {   
        createFolders(dirname($path));
        mkdir($path, 0777);   
    }   
} 
?>
<?php
if($_POST[act]){
    $type=$_FILES["file_img"]["type"];
	if($type=="image/pjpeg"||$type=="image/jpeg"){
	   $type="image/jpg";}
	   
    $name=date("Ymdhis",time()).rand(99,999).".".separation($type);
	$name2=date('Y-m-d')."/".$name;

    createFolders("../upfile"."/".date("Y-m-d")); 
	
    if($type){
        if(separation($type)==gif||separation($type)==jpg){
           $size=$_FILES["file_img"]["size"];
		   $updir = "../upfile/".date('Y-m-d')."/";//文件位置
		   $tmp_name=$_FILES["file_img"]["tmp_name"];
		   if($size<102400){
            move_uploaded_file($tmp_name,$updir.$name);
			@mysql_query("insert into photo (member_id,p_url,p_addtime) values ('".$_COOKIE['user_id']."','$name2','".date("Y-m-d H:i:s")."')");
			
			echo "<script>opener.document.form1.picture.value='$name2';window.close();</script>";exit;
		   }else
		   {
		   echo "<script>('您上传的文件大小超出范围');location='javascript:history.go(-1)';</script>";exit;
		   }
        }else
		{ 
		  echo "<script>alert('请选择正确的文件类型');location='javascript:history.go(-1)';</script>";exit;
		}
    }
    else
	{
	  echo "<script>alert('请选择您要上传的图片');location='javascript:history.go(-1)';</script>";exit;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片上传</title>
</head>
<style type="text/css">
<!--
body {
	background-color: #DFF2FF;
}
-->
</style>
<body>
<?php
if($_COOKIE[user_id]){
?>
<form name='form1' action='upfile.php' method='post' enctype='multipart/form-data'> 
<table width="90%" border="0" cellspacing="1" cellpadding="0" align="center"> 
  <tr>
   <td align='center'><input type='file' name='file_img'>&nbsp;<input type='submit' name='Submit' value='上传' class='input2'></td><input type="hidden" name="act" value="ok" />
   </tr>
   <tr>
     <td height="25" align="center">请上传JPG或GIF图像格式，图像大小限制100KB</td>
   </tr>
</table>
</form>
<?php
}else{
?>
<div align="center"><a href="javascript:window.close();"><font color="#FF0000">非法操作</font></a></div>
<?php
}?>
</body>
</html>